package com.example.hehecat.yuejian1.mvp.presenter;

import android.util.Log;

import com.example.hehecat.yuejian1.mvp.contract.IssuePictureContract;
import com.example.hehecat.yuejian1.mvp.model.IssuePictureModel;
import com.example.hehecat.yuejian1.mvp.model.bean.SuccessBean;


import okhttp3.MultipartBody;

import rx.Subscriber;

import static org.greenrobot.eventbus.EventBus.TAG;

public class IssuePicturePresenter implements IssuePictureContract.Presenter {
    private IssuePictureContract.Model model;
    private IssuePictureContract.View view;

    public IssuePicturePresenter(IssuePictureContract.View view){
        this.view = view;
        model = new IssuePictureModel();
    }

    @Override
    public void issuePicture(String picturename, String intro,int user_id, MultipartBody.Part picture1) {
        model = new IssuePictureModel();
        model.issuePicture(picturename, intro, picture1,user_id, new Subscriber<SuccessBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                Log.d(TAG, "onError: upload"+e.getMessage());
            }

            @Override
            public void onNext(SuccessBean successBean) {
                Log.d(TAG, "onNext: "+picture1.headers());
                Log.d(TAG, "onNext: "+successBean.getSuccess());
                Log.d(TAG, "onNext: "+successBean.getMsg());
                view.showdata("上传成功");
            }
        });
    }
}
